var express = require('express');
const Result = require('../lib/Result');
const isRule = require('../util/isRule');
const GoodsSkusCardValue = require('../db/models/goods/goods_skus_card_value');
var router = express.Router();
/**
 * 删除商品规格选项的值,148,13,6
 */
router.post("/:id/delete", (req, res) => {
    let token = req.auth
    if (isRule(token.rule, [148, 13, 6], res, token.super)) {
        GoodsSkusCardValue.deleteGoodsSkusCardValue(req.params.id).then(res.json(Result.success(true)))
    }
})
/**
 * 修改商品规格选项的值,147,13,6
 */
router.post("/:id", (req, res) => {
    let token = req.auth
    let goods_skus_card_id=req.body.goods_skus_card_id
    let name=req.body.name
    let order=req.body.order
    let value=req.body.value
    if (isRule(token.rule, [147, 13, 6], res, token.super)) {
        GoodsSkusCardValue.updateGoodsSkusCardValue(goods_skus_card_id,name,order,value,req.params.id).then(value=>{
            res.json(Result.success(true))
        })
    }
})
/**
 * 添加商品规格选项的值,145,13,6
 */
router.post("", (req, res) => {
    let token = req.auth
    let goods_skus_card_id=req.body.goods_skus_card_id
    let name=req.body.name
    let order=req.body.order
    let value=req.body.value
    if (isRule(token.rule, [145, 13, 6], res, token.super)) {
        GoodsSkusCardValue.addGoodsSkusCardValue(goods_skus_card_id,name,order,value).then(value=>{
            res.json(Result.success(value.toJSON()))
        })
    }
})
module.exports=router